home *** CD-ROM | disk | FTP | other *** search
/ Champak 106 / Vol 106.iso / games / global_r.swf / scripts / __Packages / Rope.as < prev    next >
Encoding:
Text File  |  2010-04-12  |  4.0 KB  |  150 lines

  1. class Rope
  2. {
  3.    var refChopper;
  4.    var bmpRope;
  5.    var bmpCanvas;
  6.    var begPos;
  7.    var endPos;
  8.    var bHasCargo;
  9.    var length;
  10.    var maxLength;
  11.    var mode;
  12.    var angle;
  13.    var maxAngle;
  14.    var angleVel;
  15.    var refCargo;
  16.    var scrPos;
  17.    function Rope(refChopperNew)
  18.    {
  19.       this.refChopper = refChopperNew;
  20.       this.bmpRope = flash.display.BitmapData.loadBitmap("rope");
  21.       this.bmpCanvas = Game.bmpShots;
  22.       this.begPos = new flash.geom.Point();
  23.       this.endPos = new flash.geom.Point();
  24.       this.bHasCargo = false;
  25.       this.length = 0;
  26.       this.maxLength = 100;
  27.       this.mode = 0;
  28.       this.angle = 0;
  29.       this.maxAngle = 1.0471975511965976;
  30.       this.angleVel = 0;
  31.       this.refCargo = null;
  32.    }
  33.    function step(begPosNew, chopVel)
  34.    {
  35.       this.begPos = begPosNew.clone();
  36.       if(this.mode == 1)
  37.       {
  38.          if(this.refCargo.sType == "vehicle")
  39.          {
  40.             if(this.length > 62)
  41.             {
  42.                this.length -= 2;
  43.             }
  44.             else if(this.length < 58)
  45.             {
  46.                this.length += 2;
  47.             }
  48.          }
  49.          else if(this.length < this.maxLength)
  50.          {
  51.             this.length += 2;
  52.          }
  53.       }
  54.       else if(this.mode == 2)
  55.       {
  56.          if(this.length > 0)
  57.          {
  58.             this.length -= 2;
  59.          }
  60.          else
  61.          {
  62.             this.refCargo = null;
  63.             this.bHasCargo = false;
  64.             this.length = 0;
  65.             this.angleVel = 0;
  66.             this.setMode(0);
  67.          }
  68.       }
  69.       if(this.length > 0)
  70.       {
  71.          this.angle += 3.141592653589793 * chopVel.x / 240;
  72.          if(this.angle > this.maxAngle)
  73.          {
  74.             this.angle += (this.maxAngle - this.angle) * 0.1;
  75.          }
  76.          else if(this.angle < - this.maxAngle)
  77.          {
  78.             this.angle += (- this.maxAngle - this.angle) * 0.1;
  79.          }
  80.          var _loc3_ = 0.006;
  81.          var _loc2_ = (- this.angle) * _loc3_;
  82.          this.angleVel += _loc2_;
  83.          this.angleVel *= 0.97;
  84.          this.angle += this.angleVel;
  85.          do
  86.          {
  87.             this.endPos.x = this.begPos.x - this.length * Math.sin(this.angle);
  88.             this.endPos.y = this.begPos.y - this.length * Math.cos(this.angle);
  89.             if(this.checkCollision() || this.endPos.y < 30)
  90.             {
  91.                this.length -= 1;
  92.             }
  93.          }
  94.          while(this.checkCollision() || this.endPos.y < 30);
  95.          
  96.          return this.endPos;
  97.       }
  98.    }
  99.    function draw(scrPosNew)
  100.    {
  101.       this.scrPos = scrPosNew.clone();
  102.       var _loc4_ = new flash.display.BitmapData(1,this.length);
  103.       _loc4_.copyPixels(this.bmpRope,this.bmpRope.rectangle,new flash.geom.Point(0,0));
  104.       var _loc2_ = new flash.geom.Matrix();
  105.       _loc2_.rotate(this.angle);
  106.       var _loc3_ = new flash.geom.Matrix();
  107.       if(this.angle > 0)
  108.       {
  109.          _loc3_.translate(this.scrPos.x,Game.screenH - this.scrPos.y);
  110.       }
  111.       else
  112.       {
  113.          _loc3_.translate(this.scrPos.x,Game.screenH - this.scrPos.y);
  114.       }
  115.       _loc2_.concat(_loc3_);
  116.       var _loc5_ = true;
  117.       this.bmpCanvas.draw(_loc4_,_loc2_,null,null,null,_loc5_);
  118.    }
  119.    function setMode(modeNew)
  120.    {
  121.       this.mode = modeNew;
  122.       if(this.mode == 1)
  123.       {
  124.          this.endPos = this.begPos.clone();
  125.       }
  126.    }
  127.    function switchMode(Void)
  128.    {
  129.       if(this.mode == 0 || this.mode == 2)
  130.       {
  131.          this.setMode(1);
  132.       }
  133.       else if(this.mode == 1)
  134.       {
  135.          this.setMode(2);
  136.          if(this.refCargo.sType == "vehicle")
  137.          {
  138.             this.refCargo.mode = 2;
  139.             this.refCargo.vel = this.refChopper.speed.clone();
  140.          }
  141.       }
  142.    }
  143.    function checkCollision(Void)
  144.    {
  145.       var _loc3_ = this.scrPos.x + (this.endPos.x - this.begPos.x);
  146.       var _loc2_ = Game.screenH - this.endPos.y;
  147.       return Game.bmpDead.hitTest(new flash.geom.Point(0,0),250,new flash.geom.Point(_loc3_,_loc2_));
  148.    }
  149. }
  150.